<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% 
String path=request.getContextPath(); 
String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; 
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<title>方案配置</title>

<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
</head>

<script type="text/javascript">
$(document).ready(function() {
		isReadyIframe();
		
		//添加/编辑成功返回该页面的提示
		 <%if(null != request.getAttribute("flag")){
			if("edit".equals(request.getAttribute("flag").toString())){%>	
				$.message("success","修改成功");
			<%}
			if("add".equals(request.getAttribute("flag").toString())){%>
				$.message("success","添加成功");
			<%}
		}%>
		
		queryCreditPlan(1);
	});
	
	function isReadyIframe(){
		var iframe = $(window.parent.document).find("#iframe").length;
		if(iframe==0){
			window.location.href="<%=basePath%>index.jsp";
		}
	}
	
	//点击“选择(合作伙伴)”
	function openChannelPageDiv(){
		queryChannelInfo(1);
	}
	
	//为查询合作伙伴 拼接参数
	function queryChannelInfo(pageIndex){
		var channelCode = $.trim($('#channelCode_choose').val());
		var channelName = $.trim($('#channelName_choose').val());
		
		loadChannelInfo({current:pageIndex,size:8,channelCode:channelCode,channelName:channelName});
	}
	
	//加载合作伙伴
	function loadChannelInfo(param){
		$.openLoading();
		$.ajax({
			url : "<%=path%>/CreditPlan/queryChannelInfoPageByCriteria?"+new Date().getTime(),
			type : 'POST',
			async : true,
			data:param,
			dataType:'json',
			success:function(page){
				$.closeLoading();
				if($.validate(page))return;
	
				var radioObj ="<input class='input_fxk' name='radioChannelInfo' type='radio' value=''>";
				var fieldNames = "channelCode,channelName";
				var tableContent = creatTable1(fieldNames,page,radioObj);
				var tableObj = $("#channelInfoTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage2(param.current,6,page.maxPage,"42");
				var pageDIV = $("#channelInfoPageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				
				$('#channelInfoDiv').OpenDiv();
				
				bindradio();
			}
		});
	}  
	
	//点击“确定”按钮，选择合作伙伴
	function chooseChannelInfo(){
		var selected = $("input[name='radioChannelInfo']:checked");
		if(selected.length==0){
			$.message("error", "请选择一个合作伙伴");
			return;
		}
		var channelCode = selected.parent().parent().children(" td:eq(1)").html();
		$('#partner_code').val(channelCode);
		
		closeChannelInfoDiv();
	}
	
	//关闭 选择合作伙伴 弹出层
	function closeChannelInfoDiv(){
		$("#channelInfoDiv").CloseDiv();	
		
		$('#channelCode_choose').val("");
		$('#channelName_choose').val("");
	}
	
	//为查询投保方案 拼接参数
	function queryCreditPlan(pageIndex){
		var partner_code = $.trim($('#partner_code').val());
		var plan_code = $.trim($('#plan_code').val());
		var plan_name = $.trim($('#plan_name').val());
		var prod_code=$.trim($('#prod_code').val());
		/* var checkStatus=$.trim($('#checkStatus').val()); */
		
		loadCreditPlan({current:pageIndex,size:10,prod_code:prod_code,partner_code:partner_code,plan_code:plan_code,plan_name:plan_name});
	}
	
	//点击"重置"方案查询条件
	function resetQueryCreditPlanCriteria(){
		$("#queryCreditPlanCriteriaTable input[type!='button']").val("");
	}
	
	
	var exportflag=false;
	//加载投保方案
	function loadCreditPlan(param){
		$.openLoading();
		$.ajax({
				url : "<%=path%>/CreditPlan/queryPlanList?"+new Date().getTime(),
				type : 'POST',
				async : true,
				dataType:'json',
				data:param,
				success : function(page) {
					$.closeLoading();
					if($.validate(page))return;
					var flag=page.obj 
					var firstbutton ='';
					if(flag){
						 firstbutton ="<input class='input_fxk' name='radioCreditPlan' type='radio' value='#'>@<input class='input_fxk' name='checkPlan' type='checkBox' value='#'>";
					}else{
						 firstbutton ="<input class='input_fxk' name='radioCreditPlan' type='radio' value='#'>"
					}
					var lastbutton = "<a href='javascript:void(0)' onClick='editCreditPlan(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='delCreditPlan(this);return false'>删除</a>";
					var tableContent = creatTable1("PLAN_CODE,PLAN_NAME,PROD_CODE,PROD_NAME,PARTNER_CODE,CHANNEL_NAME",page,firstbutton,lastbutton);
					
					var tableObj = $("#creditPlanTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					var strPage = creatChannelPage(param.current,6,page.maxPage,"83");
					var pageDIV = $("#creditPlanPageDIV");
					pageDIV[0].innerHTML="";
					exportflag=flag;
			
				 	if(flag){
						$("#implBtn").show();
					}else{
						//没有导出权限
						$("#implBtn").hide();
						if($('#creditPlanTable tr th:eq(1)').html()=="导出"){
							$('#creditPlanTable tr th:eq(1)').remove();
						}
					} 
					pageDIV.append(strPage);
					
					bindradio();//点击单选按钮，该行高亮显示
				}
			});
	}
	//点击“删除(方案)”
	function delCreditPlan(creditPlan){
		$.dialog({
			type: "warn",
			content: "您确定要删除该投保方案吗？",
			onOk: function() {
				$.openLoading();
				var delTr = $(creditPlan).parent('td').parent('tr')[0];
				var planflag=1;
				var partflag=5;
				if(exportflag){
					planflag=2;
					partflag=6;
				}
				var plan_code = delTr.childNodes[planflag].innerHTML;
				var partner_code = delTr.childNodes[partflag].innerHTML;
				$.ajax({
					url : "<%=path%>/CreditPlan/delCreditPlan?"+new Date().getTime(),
					type: "POST",
					async:true,
					data:{
						plan_code:plan_code,
						partner_code:partner_code
					},
					dataType: "json",
					success: function(data) {
						$.closeLoading();
						if($.validate(data))return;
						
						queryCreditPlan(1);
					}
				});
			}
		});
	}
	
	//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
	function bindradio(){
		$("input[name='radioCreditPlan']").click(function(){
			$("input[name='radioCreditPlan']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
		$("input[name='radioChannelInfo']").click(function(){
			$("input[name='radioChannelInfo']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
	}
	 
	//新增(方案),跳转至新增方案 页面
	function addCreditPlan(){
		window.location.href='<%=path%>/CreditPlan/toAddCreditPlan';
	}
	
	//编辑(方案),跳转至 编辑方案 页面
	function editCreditPlan(creditPlan){
		var delTr = $(creditPlan).parent('td').parent('tr')[0];
		var planflag=1;
		if(exportflag){
			planflag=2;
		}
		var plan_code = delTr.childNodes[planflag].innerHTML;
		window.location.href='<%=path%>/CreditPlan/toEditCreditPlan?plan_code='+plan_code;
	}
	
	//复制新增(方案)
	function copyAddCreditPlan(){
		var selected = $("input[name='radioCreditPlan']:checked");
		if(selected.length==0){
			$.message("error", "请选择一个投保方案");
			return;
		}
		var planflag=1;
		if(exportflag){
			planflag=2;
		}
		var plan_code = selected.parent().parent().children("td:eq("+planflag+")").html();
		window.location.href='<%=path%>/CreditPlan/toCopyAddCreditPlan?plan_code='+plan_code;
	}
	function exPlan(){
		var planCode='';
		$("input[name='checkPlan']:checked").each(function(){
			if(''==planCode){
				planCode = $(this).parent().parent().children("td:eq(2)").html()
			}else{
				planCode =planCode+","+ $(this).parent().parent().children("td:eq(2)").html()
			}
		});
		if(planCode==''){
			$.message("error", "请至少选择一个方案");
			return;
		}
		window.location.href='<%=path%>/CreditPlan/dowloadPlan?plan_code='+planCode;
	
	}
</script>
	
<body>
	<div class="current">
          <table class="current_table_1">
             <tbody>
               <tr class="f2">
                 <td><img src="./images/current_1.jpg"></td>
                 <td class="current_table_1_td">
                   <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                     <span style=" color:#136bab; ">信保产品管理
                     <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>方案配置
                 </span>
                 </td>
                 <td><img src="./images/current_3.jpg"></td>
             </tr>
          </tbody>
        </table>
     </div>
	
	<table class="table_02" id="table">
		<tr>
			<td>
				<table class="search_table" id="queryCreditPlanCriteriaTable">
					<tr height="30px">
						<td width="32%" height="30">
							<div style="display: inline-block;">
								合作伙伴代码：
								<input name="txt3"  id="partner_code" value="" readonly="readonly" style="background: #ccc;" class="input_text">
								<input type="button"  class="input_button_1" id="openChannelPageDivBtn" value="选择" onClick="openChannelPageDiv()"/>
							</div>
						</td>
						<td width="23%" height="30">产品编号：
							&nbsp;&nbsp;<input name="txt3" id="prod_code" value="" class="input_text" />
						</td>
						</tr>
						<tr height="25px">
						<td width="23%" height="30">投保方案号：
							&nbsp;<input name="txt3" id="plan_code" value="" class="input_text" />
						</td>
						<td width="25%" height="30">投保方案名称：
							<input name="txt3" id="plan_name" value=""  class="input_text" />
						</td>
						<td width="30%" height="30">
							<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryCreditPlan(1)"/>&nbsp;
							<input type="button" value="重置" onClick="resetQueryCreditPlanCriteria()" class="input_button_1" />							
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="search_table">
					<tr height="30px">
						<td width="100%" height="30">
							 <input type="button"  class="input_button_1" id="searchBtn" value="新增" onClick="addCreditPlan()"/>&nbsp;
							 <input type="button"  class="input_button_2" id="copyAddBtn" value="复制新增" onClick="copyAddCreditPlan()"/>
							 <input type="button" class="input_button_2" id="implBtn" value="导出方案" onClick="exPlan()"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table id="creditPlanTable"  class="content_table_1">
					<thead>
						<tr class="f1">
		                  <th style="width:3%">选择</th>
		                  <th style="width:3%;">导出</th>
		                  <th style="width:5%">投保方案号</th>
		                  <th style="width:8%">投保方案名称</th>
		                  <th style="width:6%">产品编号</th>
		                  <th style="width:7%">产品名称</th>
		                  <th style="width:5%">合作伙伴代码</th>
		                  <th style="width:7%">合作伙伴名称</th>
		                  <th style="width:4%">操作</th>
		              	</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
				<div id="creditPlanPageDIV"  class="page"></div>
			</td>
		</tr>
	</table>
	
	<!-- 选择 合作伙伴 div-->
  	<div id="channelInfoDiv" style="display:none;width:90%;text-align: center;">
		<div class="table_title_div">
				<table class="table_title" style='width:100%;height: 20px;'>
					<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeChannelInfoDiv()"/></td>
					</tr>
				</table>
		</div>
		<table class="table_02" style="width:98%">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
								合作伙伴代码：<input name="txt3"  id="channelCode_choose" class="input_text" />&nbsp;&nbsp;
								合作伙伴名称：<input name="txt3" id="channelName_choose" class="input_text" />&nbsp;&nbsp;
								<input type="button"  class="input_button_1" value="查询" onClick="queryChannelInfo(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="channelInfoTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="channelInfoPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" value="确定" onclick="chooseChannelInfo()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		   <input type="button" value="取消" onclick="closeChannelInfoDiv()" class="input_button_3"/>
		</div>
	</div>	
</body>
</html>